package DEEPERsource.DEEPERsource.source.util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LLLXMLReplace {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int shift = 55;
		try {
			BufferedReader reader = new BufferedReader(new FileReader("resource/genic_interaction_data_coref.xml"));
			String s;
			StringBuffer sb = new StringBuffer("");
			Pattern p = Pattern.compile("LLL\\.d(\\d+)");
			while((s = reader.readLine())!=null){
				Matcher m = p.matcher(s);
				if(m.find()){
					int ind = Integer.parseInt(m.group(1));
					int newInd = ind+shift;
					s = s.replace("LLL.d"+ind+".s"+ind, "LLL.d"+newInd+".s"+newInd);
					s = s.replace("LLL.d"+ind, "LLL.d"+newInd);
				}
				sb.append(s);
				sb.append("\n");
			}
			reader.close();
			PrintWriter writer = new PrintWriter("resource/genic_interaction_data_coref_mod.xml");
			writer.append(sb.toString());
			writer.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
